package join;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;
import java.io.IOException;

/*
 * map类使key,value分别进行处理
 */
public class PersonAddreMap extends Mapper<LongWritable, Text, BeanKey, Bean> {
    @Override
    protected void map(LongWritable key, Text value,
                       Mapper<LongWritable, Text, BeanKey, Bean>.Context context)
            throws IOException, InterruptedException {
        String line = value.toString();
        String str[] = line.split(" ");
        if (str.length == 2) {
            // Addre表
            Bean Addre = new Bean();
            Addre.setAddreNo(str[0]);
            Addre.setAddreName(str[1]);

            BeanKey AddreKey = new BeanKey();
            AddreKey.setAddreNo(Integer.parseInt(str[0]));
            AddreKey.setPrimary(true); // true表示地区表
            context.write(AddreKey, Addre);
        } else {
            // Person表
            Bean Person = new Bean();
            Person.setUserNo(str[0]);
            Person.setUserName(str[1]);
            Person.setAddreNo(str[2]);

            BeanKey PerKey = new BeanKey();
            PerKey.setAddreNo(Integer.parseInt(str[2]));
            PerKey.setPrimary(false);// false表示人员表
            context.write(PerKey, Person);

        }
    }

}

